package com.java.framework.interceptor.impl;

import com.java.common.token.TokenUtil;
import com.java.common.utils.tool.StringUtils;
import com.java.framework.interceptor.LoginInterceptor;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * 判断是否登录
 */
@Component
public class LoginUrlInterceptor extends LoginInterceptor {

    @SuppressWarnings("unchecked")
    @Override
    public boolean isLogin(HttpServletRequest request) {
        boolean isLogin = false;
        String tokenWEB = request.getParameter("tokenWEB");
        String tokenAPP = request.getParameter("tokenAPP");
        String userId = request.getParameter("userId");
        if (StringUtils.isNotEmpty(userId)) {
            if (StringUtils.isNotEmpty(tokenWEB)) {
                isLogin = TokenUtil.isLoginWEB(userId, tokenWEB);
            }
            if (StringUtils.isNotEmpty(tokenAPP)) {
                isLogin = TokenUtil.isLoginAPP(userId, tokenAPP);
            }
        }
        return isLogin;
    }
}
